#!/bin/sh
# Copyright (C) 2014-2017 by Thomas Auzinger <thomas@auzinger.name>

# Replace the 'x' in the next line with the name of the thesis' main LaTeX document without the '.tex' extension
SOURCE=z1_ot

function with_error_checking()
{
	rm *.bbl
	# Build the thesis document
	pdflatex $SOURCE && \
	bibtex   $SOURCE && \
	pdflatex $SOURCE && \
	pdflatex $SOURCE && \
	makeindex -t $SOURCE.glg -s $SOURCE.ist -o $SOURCE.gls $SOURCE.glo && \
	makeindex -t $SOURCE.alg -s $SOURCE.ist -o $SOURCE.acr $SOURCE.acn && \
	makeindex -t $SOURCE.ilg -o $SOURCE.ind $SOURCE.idx && \
	pdflatex $SOURCE && \
	pdflatex $SOURCE && \
	echo Thesis document compiled. ||
	echo Something failed.
}

function force()
{
	# Build the thesis document
	pdflatex $SOURCE
	bibtex   $SOURCE
	pdflatex $SOURCE
	pdflatex $SOURCE
	makeindex -t $SOURCE.glg -s $SOURCE.ist -o $SOURCE.gls $SOURCE.glo
	makeindex -t $SOURCE.alg -s $SOURCE.ist -o $SOURCE.acr $SOURCE.acn
	makeindex -t $SOURCE.ilg -o $SOURCE.ind $SOURCE.idx
	pdflatex $SOURCE
	pdflatex $SOURCE
	echo Thesis document compiled.
}

if [ $1 = 'f' ]; then
	force
else
	with_error_checking
fi
